package homework10_String;

/**
 * @author admin
 * @version 1.0
 * @date 2024-04-05 22:43
 */

public class Test04 {
    public static void main(String[] args) {
        /**
         * 给定两个以字符串形式表示的非负整数num1和num2，返回num1和num2的乘积，他们的乘积也表示为字符串形式
         */
        String str1="123456";
        String str2="789";
        int []arr1=new int[str1.length()];
        int []arr2=new int[str2.length()];
        arr1=turnIntoArr(str1);
        arr2=turnIntoArr(str2);
        int num1=turnIntoNum(arr1);
        int num2=turnIntoNum(arr2);
        StringBuilder sb=new StringBuilder();
        System.out.println(sb.append(num1*num2).toString());
    }
    public static int[] turnIntoArr(String str){
        int[] arr=new int[str.length()];
        for (int end=str.length()-1;end>=0;end--){
            char c=str.charAt(end);
            int num=c-'0';
            arr[str.length()-end-1]=num;
        }
        return arr;
    }
    public static int turnIntoNum(int[] arr){
        int num=0;
        for (int i = 0; i < arr.length; i++) {
            switch (i){
                case 0:
                    num+=arr[i];
                    break;
                case 1:
                    num+=arr[i]*10;
                    break;
                case 2:
                    num+=arr[i]*10*10;
                    break;
                case 3:
                    num+=arr[i]*10*10*10;
                    break;
                case 4:
                    num+=arr[i]*10*10*10*10;
                    break;
                case 5:
                    num+=arr[i]*10*10*10*10*10;
                    break;
                case 6:
                    num+=arr[i]*10*10*10*10*10*10;
                    break;
                case 7:
                    num+=arr[i]*10*10*10*10*10*10*10;
                    break;
                case 8:
                    num+=arr[i]*10*10*10*10*10*10*10*10;
                    break;
                case 9:
                    num+=arr[i]*10*10*10*10*10*10*10*10*10;
                    break;
            }
        }
        return num;
    }
}
